home *** CD-ROM | disk | FTP | other *** search
- /*
- * search_ti_entry.c
- *
- * thanks libc d_import.c
- */
-
- #include<stddef.h>
- #include<string.h>
- #define __DOS_INLINE__
- #include<sys/dos.h>
- #include"tcpipdrv.h"
-
- /* structs */
- struct _memimg {
- struct _mep mep;
- struct _psp psp;
- char prog[0];
- };
-
- /* Macros */
- #define _GETMP(psp) ((char *) (psp) - sizeof (struct _mep))
- #define _ISKEEPMEM(x) (((int) (x) & 0xff000000) == 0xff000000)
-
- /* file scope variables */
- static _ti_func func;
- static int failed;
- static int super_p;
- #ifdef FAST_API
- static int trap_no = -2;
- #endif
-
- /* file scope functions */
- static void * search_ti_sub (void);
- static long _ti_entry (long, void *);
- static long _ti_entry_super (long, void *);
- #ifdef FAST_API
- static long _ti_entry_trap_0 (long, void *);
- static long _ti_entry_trap_1 (long, void *);
- static long _ti_entry_trap_2 (long, void *);
- static long _ti_entry_trap_3 (long, void *);
- static long _ti_entry_trap_4 (long, void *);
- static long _ti_entry_trap_5 (long, void *);
- static long _ti_entry_trap_6 (long, void *);
- static long _ti_entry_trap_7 (long, void *);
-
- typedef long (*trap_func) (long, void *);
- static trap_func trap_funcs[8] =
- {
- _ti_entry_trap_0,
- _ti_entry_trap_1,
- _ti_entry_trap_2,
- _ti_entry_trap_3,
- _ti_entry_trap_4,
- _ti_entry_trap_5,
- _ti_entry_trap_6,
- _ti_entry_trap_7,
- };
- #endif
-
- /*
- **
- */
- _ti_func
- search_ti_entry (void)
- {
- long ssp;
-
- if (failed)
- return NULL;
-
- if (!func)
- {
- super_p = 0;
- ssp = _dos_super (0);
- func = search_ti_sub ();
- if (ssp > 0)
- _dos_super (ssp);
-
- if (_dos_memcpy (func - 8, func - 8, 1))
- super_p = 1;
- }
-
- if (!func)
- {
- failed = 1;
- return func;
- }
-
- #ifdef FAST_API
- if (trap_no >= 0 && trap_no <= 7)
- return trap_funcs[trap_no];
- else if (trap_no == -2)
- {
- trap_no = _ti_entry (-1, NULL);
- if (trap_no >= 0 && trap_no <= 7)
- return trap_funcs[trap_no];
- else
- trap_no = -1;
- }
- #endif
-
- if (super_p)
- return _ti_entry_super;
- else
- return _ti_entry;
- }
-
- /*
- **
- */
- void *
- search_ti_sub (void)
- {
- void *addr;
- struct _memimg *ps;
- struct _psp *psp;
-
- psp = _dos_getpdb ();
- addr = 0;
-
- ps = (struct _memimg *) _GETMP (psp);
-
- while (ps = ps->mep.prev_mp)
- {
- if (_ISKEEPMEM (ps->mep.parent_mp))
- {
- if (!strncmp (ps->prog, "TCP/IP", 6))
- {
- addr = ps->prog + 8;
- break;
- }
- }
- }
-
- /* addr é≡ò╘é╖ */
- return addr;
- }
-
- /*
- **
- */
- static long
- _ti_entry (long arg1, void *arg2)
- {
- register long result asm ("d0");
-
- asm volatile ("move.l\t%2,a0\n"
- "\tmove.l\t%1,d0\n"
- "\tmove.l\t%3,a1\n"
- "\tjsr\t(a1)\n"
- : "d=" (result)
- : "g" (arg1), "g" (arg2), "g" (func)
- : "d0", "d1", "d2", "a0", "a1", "a2");
-
- return result;
- }
-
- /*
- **
- */
- static long
- _ti_entry_super (long arg1, void *arg2)
- {
- register long result asm ("d0");
-
- asm volatile ("move.l\t%2,a0\n"
- "\tmove.l\t%1,d0\n"
- "\tmove.l\t%3,-(sp)\n"
- "\tDOS\tSUPER_JSR\n"
- "\taddq.l\t#4,sp"
- : "d=" (result)
- : "g" (arg1), "g" (arg2), "g" (func)
- : "d0", "d1", "d2", "a0", "a1", "a2");
-
- return result;
- }
-
- #ifdef FAST_API
- /*
- **
- */
- static long
- _ti_entry_trap_0 (long arg1, void *arg2)
- {
- register long result asm ("d0");
-
- asm volatile ("move.l\t%2,a0\n"
- "\tmove.l\t%1,d0\n"
- "\ttrap\t#0\n"
- : "d=" (result)
- : "g" (arg1), "g" (arg2)
- : "d0", "d1", "d2", "a0", "a1", "a2");
-
- return result;
- }
-
- /*
- **
- */
- static long
- _ti_entry_trap_1 (long arg1, void *arg2)
- {
- register long result asm ("d0");
-
- asm volatile ("move.l\t%2,a0\n"
- "\tmove.l\t%1,d0\n"
- "\ttrap\t#1\n"
- : "d=" (result)
- : "g" (arg1), "g" (arg2)
- : "d0", "d1", "d2", "a0", "a1", "a2");
-
- return result;
- }
-
- /*
- **
- */
- static long
- _ti_entry_trap_2 (long arg1, void *arg2)
- {
- register long result asm ("d0");
-
- asm volatile ("move.l\t%2,a0\n"
- "\tmove.l\t%1,d0\n"
- "\ttrap\t#2\n"
- : "d=" (result)
- : "g" (arg1), "g" (arg2)
- : "d0", "d1", "d2", "a0", "a1", "a2");
-
- return result;
- }
-
- /*
- **
- */
- static long
- _ti_entry_trap_3 (long arg1, void *arg2)
- {
- register long result asm ("d0");
-
- asm volatile ("move.l\t%2,a0\n"
- "\tmove.l\t%1,d0\n"
- "\ttrap\t#3\n"
- : "d=" (result)
- : "g" (arg1), "g" (arg2)
- : "d0", "d1", "d2", "a0", "a1", "a2");
-
- return result;
- }
-
- /*
- **
- */
- static long
- _ti_entry_trap_4 (long arg1, void *arg2)
- {
- register long result asm ("d0");
-
- asm volatile ("move.l\t%2,a0\n"
- "\tmove.l\t%1,d0\n"
- "\ttrap\t#4\n"
- : "d=" (result)
- : "g" (arg1), "g" (arg2)
- : "d0", "d1", "d2", "a0", "a1", "a2");
-
- return result;
- }
-
- /*
- **
- */
- static long
- _ti_entry_trap_5 (long arg1, void *arg2)
- {
- register long result asm ("d0");
-
- asm volatile ("move.l\t%2,a0\n"
- "\tmove.l\t%1,d0\n"
- "\ttrap\t#5\n"
- : "d=" (result)
- : "g" (arg1), "g" (arg2)
- : "d0", "d1", "d2", "a0", "a1", "a2");
-
- return result;
- }
-
- /*
- **
- */
- static long
- _ti_entry_trap_6 (long arg1, void *arg2)
- {
- register long result asm ("d0");
-
- asm volatile ("move.l\t%2,a0\n"
- "\tmove.l\t%1,d0\n"
- "\ttrap\t#6\n"
- : "d=" (result)
- : "g" (arg1), "g" (arg2)
- : "d0", "d1", "d2", "a0", "a1", "a2");
-
- return result;
- }
-
- /*
- **
- */
- static long
- _ti_entry_trap_7 (long arg1, void *arg2)
- {
- register long result asm ("d0");
-
- asm volatile ("move.l\t%2,a0\n"
- "\tmove.l\t%1,d0\n"
- "\ttrap\t#7\n"
- : "d=" (result)
- : "g" (arg1), "g" (arg2)
- : "d0", "d1", "d2", "a0", "a1", "a2");
-
- return result;
- }
- #endif
-